package com.feiyu.gateway.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.auth0.jwt.interfaces.JWTVerifier;

import java.util.Map;

/**
 * @author tang ming
 * @since 2021/12/9 16:19
 */
public class JwtUtil {

    public static JWTVerifier verifier = JWT.require(Algorithm.HMAC256(Constants.SING_KEY

    )).build();
    public static Map<String, Claim> decodeToken(String token)  {
        try {
            DecodedJWT jwt = verifier.verify(token);
            return jwt.getClaims();
        } catch (Exception ignored) {}
        return null;
    }

    public static boolean isExpire(String token){
        try {
            DecodedJWT jwt = verifier.verify(token);
        } catch (Exception e) {
            return true;
        }
        return false;
    }
}
